<template>
  <div>
    <!-- 指导记录 -->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="姓名" width="300">
        <template slot-scope="scope">
          <router-link
            :to="{
              path: '/write_record',
              query: {
                student_num: scope.row.student_num,
              },
            }"
          >
            {{ scope.row.student_name }}
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="学号" width="300">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.student_num }}</span>
        </template>
      </el-table-column>
      <el-table-column label="专业" width="300">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.student_class }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">
            <router-link
              :to="{
                path: '/write_record',
                query: { student_num: scope.row.student_num },
              }"
            >
              填写指导记录</router-link
            >
          </el-button>
          <!-- <el-button size="mini" @click="look(scope.row)">查看</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="给该学生的指导记录" :visible.sync="dialogVisible">
      <el-table :data="tableDatas" style="width: 100%">
        <el-table-column prop="date" label="日期" width="180">
        </el-table-column>
        <el-table-column prop="address" label="内容"> </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  created() {
    this.getstudentinfo();
  },
  data() {
    return {
      tableData: [],
      tableDatas: [],
      dialogVisible: false,
    };
  },
  methods: {
    // 获取所带学生信息
    getstudentinfo() {
      this.$http
        .get("http://127.0.0.1:8080/teacher/getStudentInfo")
        .then((res) => {
          // console.log(res);
          if (res.data.status == 0) {
            res.data.data.resul.forEach((value) => {
              res.data.data.result.forEach((val) => {
                if (value.student_num === val.student_num) {
                  Object.assign(val, { topic_name: value.topic_name });
                }
              });
            });
            this.tableData = res.data.data.result;
            // console.log(this.tableData);
          }
        });
    },
    handleEdit(index, row) {
      console.log(index, row);
    },
    // look(row) {
    //   this.dialogVisible = true;
    //   this.$http.post("");
    //   console.log(row);
    // },
  },
};
</script>
<style lang="less" scoped>
</style>
